home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / dev / e / yaec.lha / examples / publicscreen.e < prev    next >
Text File  |  2001-08-12  |  3KB  |  72 lines

  1. -> publicscreen.e - open a screen with the pens from a public screen
  2.  
  3. MODULE 'intuition/screens'
  4.  
  5. ENUM ERR_NONE, ERR_SCRN, ERR_LOCKPUB, ERR_GETDRAW
  6.  
  7. RAISE ERR_SCRN    IF OpenScreenTagList()=NIL
  8. RAISE ERR_LOCKPUB IF LockPubScreen()=NIL
  9. RAISE ERR_GETDRAW IF GetScreenDrawInfo()=NIL
  10.  
  11. PROC main()
  12.   IF KickVersion(37)
  13.     -> Check the version.  Release 2 is required for public screen functions
  14.     -> E-Note: E automatically opens the Intuition library
  15.     usePubScreenPens()
  16.   ENDIF
  17. ENDPROC
  18.  
  19. -> Open a screen that uses the pens of an existing public screen (the Workbench
  20. -> screen in this case).
  21. PROC usePubScreenPens() HANDLE
  22.   DEF my_screen=NIL:PTR TO screen, pubScreenName
  23.   DEF pub_screen=NIL:PTR TO screen, screen_drawinfo=NIL:PTR TO drawinfo
  24.  
  25.   pubScreenName:='Workbench'
  26.  
  27.   -> Get a lock on the Workbench screen
  28.   -> E-Note: automatically error-checked (automatic exception)
  29.   pub_screen:=LockPubScreen(pubScreenName)
  30.  
  31.   -> Get the DrawInfo structure from the locked screen
  32.   -> E-Note: automatically error-checked (automatic exception)
  33.   screen_drawinfo:=GetScreenDrawInfo(pub_screen)
  34.  
  35.   -> The pens are copied in the OpenScreenTagList() call, so we can simply use
  36.   -> a pointer to the pens in the tag list.
  37.   ->
  38.   -> This works better if the depth and colors of the new screen matches that
  39.   -> of the public screen.  Here we are forcing the Workbench screen pens on a
  40.   -> monochrome screen (which may not be a good idea).  You could add the tag:
  41.   ->      (SA_DEPTH, screen_drawinfo.depth)
  42.   -> E-Note: automatically error-checked (automatic exception)
  43.   my_screen:=OpenScreenTagList(NIL,
  44.                               [SA_PENS, screen_drawinfo.pens,
  45.                               /* E-Note: try uncommenting next line (see above) */
  46.                               /* SA_DEPTH, screen_drawinfo.depth,               */
  47.                                NIL])
  48.  
  49.   -> We no longer need to hold the lock on the public screen or a copy of its
  50.   -> DrawInfo structure as we now have our own screen.  Release the screen.
  51.   FreeScreenDrawInfo(pub_screen, screen_drawinfo)
  52.   screen_drawinfo:=NIL
  53.   UnlockPubScreen(pubScreenName, pub_screen)
  54.   pub_screen:=NIL
  55.  
  56.   Delay(90)  -> Should be the rest of the program
  57.  
  58.   -> E-Note: exit and clean up via handler
  59. EXCEPT DO
  60.   -> The first two are freed in the main code if OpenScreenTagList() does not
  61.   -> fail.  If something goes wrong, free them here.
  62.   IF screen_drawinfo THEN FreeScreenDrawInfo(pub_screen, screen_drawinfo)
  63.   IF pub_screen THEN UnlockPubScreen(pubScreenName, pub_screen)
  64.   IF my_screen THEN CloseScreen(my_screen)
  65.   -> E-Note: we can print a minimal error message
  66.   SELECT exception
  67.   CASE ERR_SCRN;    WriteF('Error: Failed to open custom screen\n')
  68.   CASE ERR_LOCKPUB; WriteF('Error: Failed to locked public screen\n')
  69.   CASE ERR_GETDRAW; WriteF('Error: Failed to get DrawInfo of screen\n')
  70.   ENDSELECT
  71. ENDPROC
  72.